package com.itlaobing.control;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.*;
import javax.servlet.http.*;

import com.itlaobing.service.UserService;

import javax.servlet.annotation.*;

@WebServlet("/RegisterControl")
public class RegisterControl extends HttpServlet{

	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//设置字符编码
		resp.setContentType("text/html;charset=UTF-8");
		PrintWriter out = resp.getWriter();
		//获取表单数据
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		out.println("<p>" +username+ "</p>"
				+ "<p>" +password+ "</p>");
		//创建UserService对象，用于向下传递所要存储的数据
		UserService auserservice = new UserService();
		//调用save方法向下传递数据
		try {
			int i = auserservice.save(username, password);
			out.println("成功存入" + i + "条数据");
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req,resp);
	}
}
